package com.ddq.springboot_mongodb.controller;

import com.ddq.springboot_mongodb.entity.User;
import com.ddq.springboot_mongodb.param.DeleteUserParam;
import com.ddq.springboot_mongodb.param.FindUserParam;
import com.ddq.springboot_mongodb.service.Mongoservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * @author ：Dongdequan
 * @date ：Created in 2022/4/1 14:22
 * @modified By：
 */
@RestController
@RequestMapping("/mongodb")
public class MongoController {

    @Autowired
    private Mongoservice mongoService;

    @PostMapping("/hello")
    public String test() {
        return "hello!";
    }

    @PostMapping("/findUser")
    public Optional<User> findUser(@RequestBody FindUserParam param) {
        return mongoService.findUser(param);
    }

    @PostMapping("/findAll")
    public List<User> findAll() {
        return mongoService.findAll();
    }

    @PostMapping("/updateUser")
    public String updateUser(@RequestBody User param) {
        return mongoService.updateUser(param);
    }

    @PostMapping("/insertUser")
    public String insertUser(@RequestBody User param) {
        return mongoService.insertUser(param);
    }

    @PostMapping("/delete")
    public String deleteUser(@RequestBody DeleteUserParam param) {
        return mongoService.deleteUser(param);
    }
}
